--[[
世界关卡
]]
local WorldLevelData = require("app.data.level.WorldLevelData")
local BaseScene = require("engin.mvcs.view.BaseScene")
local WorldLevelScene = class("WorldLevelScene", BaseScene)





	
function WorldLevelScene:ctor()
	WorldLevelScene.super.ctor(self,param)
    

    --添加 场景  并全屏显示
    cc.FileUtils:getInstance():addSearchPath("res/worldLevel/")
  	local node = cc.CSLoader:createNode("worldLevel/worldLevel.csb"):addTo(self)
	node:setContentSize(cc.size(display.width,display.height));
	ccui.Helper:doLayout(node)

	
	
	local ScrollView_2 = node:getChildByName("ScrollView_2");
	ScrollView_2:jumpToBottom();
	ScrollView_2:addTouchEventListener(handler(self,self.enter_handle))
	
	
   --[[关卡选择界面
    local PageView_SelectPage = cc.uiloader:seekNodeByName(self, "PageView_SelectPage");
    local function pageViewEvent(sender, eventType)
        if eventType == ccui.PageViewEventType.turning then
            local pageView = sender
            local level = pageView:getCurPageIndex() + 1;
            self:Button_Enter_Handle(level);
        end
    end 
    PageView_SelectPage:addEventListener(pageViewEvent)
	]]
	
	
end





local function getTouchLevel(self,position)
	for i = 1,52,1 do  --x遍历
		local name = "Sprite_Normal_"..i;
		local Sprite_Normal_1 = cc.uiloader:seekNodeByName(self, name);
		if Sprite_Normal_1:hitTest(position) then
 			return Sprite_Normal_1,i;
		end
	end
end
function WorldLevelScene:enter_handle(sender,eventType)
	
	local position = sender:getTouchEndPosition ();
	if eventType == ccui.TouchEventType.began then
	 	self.touchLevelSprite_ = getTouchLevel(self,position)
	elseif eventType == ccui.TouchEventType.ended then
		local touchLevelSprite,level = getTouchLevel(self,position)
		if self.touchLevelSprite_ == touchLevelSprite and 
		self.touchLevelSprite_ ~= nil then
		--local cbl = {GL_SRC_ALPHA , GL_ONE};
    		--Sprite_Normal_1:setBlendFunc(cc.blendFunc(gl.ONE, gl.ONE))
	        local param = SceneConstants.FightLoadingScene();
		    param.param ={
		    	level =  level
		    }
		    app:enterScene(param)
		end
    end
end 




return WorldLevelScene
